<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('短信用户列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                工号：<input type="text" name="userId" id="userId"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="userName"/>
                            </li>
                            <li>
                                手机号：<input type="text" name="telphone" width="20"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<script th:inline="javascript">
    var prefix = ctx + "pub/sms";

    $(function () {
		querySMSUserList();
    });

    function querySMSUserList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            // exportUrl: prefix + "/export",
            // importUrl: prefix + "/importData",
            // importTemplateUrl: prefix + "/importTemplate",
            // sortName: "createTime",
            // sortOrder: "desc",
            modalName: "短信用户信息",
            firstLoad: false,
            clickToSelect: true,
            singleSelect: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'userId',
                    title: '工号'
                },
                {
                    field: 'userName',
                    title: '姓名',
                },
                {
                    field: 'wardCode',
                    title: '科室编码'
                },
                {
                    field: 'wardName',
                    title: '科室名称',
                },
                {
                    field: 'telphone',
                    title: '手机'
                },
				{
					title: '用户状态',
					align: 'center',
					formatter: function (value, row, index) {
						return statusTools(row);
					}
				},
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

	/* 用户状态显示 */
	function statusTools(row) {
		if (row.enable == '0') {
			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
		} else {
			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
		}
	}

    /* 用户管理-停用 */
    function disable(id) {
        $.modal.confirm("确认要停用用户吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "enable": '0' });
        })
    }

    /* 用户管理启用 */
    function enable(id) {
        $.modal.confirm("确认要启用用户吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "enable": '1' });
        })
    }
</script>
</body>
</html>